$(function() {
	ajaxTable();
	setDialogSearch();
	closeDialogSearch();
});
function ajaxTable() {
	$('#invmaTable').datagrid({
		toolbar : [ {
			id : 'toolbarSearch',
			text : '查找',
			iconCls : 'icon-search',
			handler : function() {
				openDialogSearch();
			}
		}
		],
		frozenColumns:[[
			{field:"ck", checkbox:true}
		]],
		pageNumber : 1,
		loadMsg : '数据加载中,请稍后...',
		pageList : [ 10, 30, 50, 100 ],
		onLoadError : function() {
			alert('数据加载失败!');
		},
		queryParams : {
			maaa : $("#searchMaaa").combobox("getValue"),
			maab : $("#searchMaab").val(),
			maac : $("#searchMaac").combobox("getValue"),
			startMaad : $("#searchStartMaad").datebox("getValue"),
			endMaad : $("#searchEndMaad").datebox("getValue")
		},
		onClickRow : function(rowIndex, rowData) {
			$('#invmaTable').datagrid('unselectRow', rowIndex);
		},
		onDblClickRow : function(rowIndex, rowData) {
			openDialogBody(rowData.maaa,rowData.maab);
	    }
	}).datagrid('acceptChanges');
}
function reloadTable() {
	$('#invmaTable').datagrid('reload');
	$('#invmaTable').datagrid('clearSelections');
}
function setDialogSearch() {
	$('#invmaSearch').dialog({
		title : '查询',
		modal : true,
		left : 50,
		top : 50,
		collapsible : true,
		resizable : true
	});
}
function openDialogSearch() {
	$('#invmaSearch').dialog('open');
}
function closeDialogSearch() {
	$('#invmaSearch').dialog('close');
}
function searchInvma() {
	var queryParams = $('#invmaTable').datagrid('options').queryParams;
	queryParams.maaa = $("#searchMaaa").combobox("getValue");
	queryParams.maab = $("#searchMaab").val();
	queryParams.maac = $("#searchMaac").combobox("getValue");
	queryParams.startMaad = $("#searchStartMaad").datebox("getValue");
	queryParams.endMaad = $("#searchEndMaad").datebox("getValue");
	reloadTable();
	closeDialogSearch();
}
function maacFormater(value, row, index) {
	if(row.maac == "Y") {
		return "已审核";
	} else if(row.maac == "C") {
		return "已结束";
	} else if(row.maac == "V") {
		return "已作废";
	}
	return "未审核";

}
//----------------采购订单单身
function openDialogBody(maaa,maab) {
	var url = '/wms/invmb/invmbMain.xhtml?maaa=' + maaa +'&maab='+maab;		
	window.showModalDialog(url,"","dialogWidth=1000px; dialogHeight=700px; help=no; status=no; scroll=yes; resizable=no;");
	$('#invmaTable').datagrid('clearSelections');
	reloadTable();
}
